<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: Mr.Zhang
  Date: 2018/3/22
  Time: 11:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("UTF-8");

    //获取表单提交的数据
    String  id=request.getParameter("id");
    String name=request.getParameter("userName");
    String password=request.getParameter("password");

    Connection connection=null;
    PreparedStatement statement=null;
    ResultSet resultSet=null;

    String sql="UPDATE t_users SET id=?,userName=?,password=? WHERE id=?";

    Class.forName("com.mysql.jdbc.Driver");

    connection= DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/sctu_javaweb_2018?useUnicode=true&characterEncoding=UTF-8",
            "root",
            "123456"
    );
    statement=connection.prepareStatement(sql);

    statement.setString(1, id);
    statement.setString(2,name);
    statement.setString(3,password);
    statement.setInt(4, Integer.parseInt(id));
    int result=statement.executeUpdate();
    String msg="更新失败！";
    if (result==1){
        msg="更新成功！";
    }

    statement.close();
    connection.close();
    //resultSet=statement.executeQuery(sql);
%>
<script>window.alert('<%=msg%>');</script>
<%
    response.setHeader("Refresh","1;url=userList.jsp");
%>

